package cn.tedu.coolshark.mapper;

import cn.tedu.coolshark.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {
    @Insert("insert into product values(null,#{title},#{url},#{price},#{oldPrice},0,#{saleCount},#{created},#{categoryId})")
    void insert(Product product);

    @Select("select id,title,price,sale_count,url from product")
    @Result(property = "saleCount",column = "sale_count")
    List<Product> select();

    @Delete("delete from product")
    void deleteById(int id);

    @Select("select url from product where id=#{id}")
    String selectUrlById(int id);

    @Select("select url,price,title,old_price,sale_count from product")
    @Result(property = "saleCount",column = "sale_count")
    @Result(property = "oldPrice",column = "old_price")
    List<Product> selectindex();

    @Select("select id,title,sale_count from product order by sale_count desc limit 1,6")
    @Result(property = "saleCount",column = "sale_count")
    List<Product> selectTop();

    @Select("select url,price,title,old_price,sale_count from product where category_id=#{cid}")
    @Result(property = "saleCount",column = "sale_count")
    @Result(property = "oldPrice",column = "old_price")
    List<Product> selectByCid(int cid);


}